<script>
	import {
		addDevice,
		getConfigs
	} from '@/api/user.js'
	import appUpdate from '@/uni_modules/leruge-app-update/js_sdk/leruge-app-update.js'
	export default {
		data() {
			return {

			};
		},
		onShow() {
			/*#ifdef APP-PLUS*/
			const systemInfo = uni.getSystemInfoSync()
			uni.getSystemInfo({
				success: (res) => {
					let version = res.appWgtVersion;
					// let version = '1.3.12';
					this.version = parseInt(version.split(".").join(""));
					// console.log(this.version); 
					getConfigs({
						name: 'version'
					}).then((res) => {
						let sversion = parseInt(res.data.value.split(".").join(""))
						console.log(sversion)
						console.log(this.version < sversion)
						if (this.version < sversion) {
							if (systemInfo.platform === 'android') {
								let updateInfo = {
									platform: 'android',
									updateContent: '1.新版本',
									downUrl: 'http://down.guoshangufen.com/download/gsyy.apk',
									version: res.data.value,
									force: true,
									mainColor: '0c80fb',
								}
								appUpdate(updateInfo)
							} else {
								let updateInfo = {
									platform: 'ios',
									updateContent: '1.新版本',
									downUrl: 'https://apps.apple.com/cn/app/id6739860791',
									version: res.data.value,
									force: true,
									mainColor: '0c80fb',
								}
								appUpdate(updateInfo)
							}
						}
					});
				}
			});
			/*#endif*/
		},
		onLaunch() {
			uni.onPushMessage((res) => {
				// 监听通知栏消息的点击  
				if (res.type == 'click') {
					// 如果需要跳转app内指定页面，则自己实现下方的跳转代码。  
					uni.navigateTo({
						url: '/pages/innerinfo/innerinfo'
					})
				}
				// 监听在线推送消息，若云函数设置了 "force_notification":true，则不会触发此 receive。  
				if (res.type == 'receive') {
					if (res.data.payload) {
						console.log(res.data.payload.badge)
						if (res.data.payload.badge == 0) {
							plus.runtime.setBadgeNumber(-1);
						} else {
							plus.runtime.setBadgeNumber(res.data.payload.badge);
						}
					} else {
						uni.createPushMessage({
							title: res.data.title,
							content: res.data.content,
							success: (res1) => {
								console.log(res1)
							},
							fail: (res1) => {
								console.log(res1)
							}
						})
					}
				}
			})
		}
	};
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	/*每个页面公共css */
</style>